/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package botlab.level;

import botlab.Entity;
import botlab.Game;
import botlab.command.BaseCommand;
import botlab.compiler.CommandCreator;
import botlab.control.CameraControl;
import botlab.control.LooseCollisionControl;
import botlab.control.EndTimerControl;
import botlab.control.PatrolControl;
import botlab.control.WinCollisionControl;
import com.jme3.math.Vector3f;
import com.jme3.scene.Node;
import java.io.IOException;
import java.io.InputStream;
import java.util.logging.Logger;

/**
 *
 * @author Quentin
 */
public class LevelGoThrough extends Level
{

    private Node skyNode;
    
    public LevelGoThrough(String name)
    {
        super(name);
    }
    
    public String getSolution()
    {
        return super.getSolution("levelGoThrough");
    }
    
    @Override
    public void load()
    {
        skyNode = (Node) assetManager.loadModel("Models/base/base.j3o");
        skyNode.setName("sky_node");
        levelNode.attachChild(skyNode);
        
        Entity wall = new Entity(
                "Models/terrain/Corridor.j3o", 
                0.0f, 
                new Vector3f(0.f, 0.f, 0.f),
                0.3f,
                Entity.PhysicsType.STATIC);
        
        Entity goal = new Entity(
                "Models/goal/objectif.j3o",
                1.f,
                new Vector3f(0.f, 10.f, 180.f),
                3.f,
                Entity.PhysicsType.DYNAMIC);
        
//        Entity coin = new Entity(
//                "Models/goal/Coin.j3o", 
//                0.0f, 
//                new Vector3f(0.f, 10.f, 0.f),
//                1f,
//                Entity.PhysicsType.STATIC);
//        
//        Entity star = new Entity(
//                "Models/goal/Star.j3o", 
//                0.0f, 
//                new Vector3f(10.f, 10.f, 0.f),
//                1f,
//                Entity.PhysicsType.STATIC);
        
        Entity ship = new Entity(
                "Models/vaisseau1/vaisseau1.j3o",
                1.f,
                new Vector3f(0.f, 10.f, -100.f),
                1.f,
                Entity.PhysicsType.DYNAMIC);
        
        Entity enemy1 = new Entity(
                "Models/ennemis/shipspace1/Plane1.j3o",
                0.f, 
                new Vector3f(0f,0f,0f),
                1.f,
                Entity.PhysicsType.KINEMATIC);
        
        Entity enemy2 = new Entity(
                "Models/ennemis/shipspace1/Plane1.j3o",
                0.f, 
                new Vector3f(0.f,0.f, 0.f),
                1.f,
                Entity.PhysicsType.KINEMATIC);
        
        Entity enemy3 = new Entity(
                "Models/ennemis/shipspace1/Plane1.j3o",
                0.f, 
                new Vector3f(0.f,0.f, 0.f),
                1.f,
                Entity.PhysicsType.KINEMATIC);
        
        Entity enemy4 = new Entity(
                "Models/ennemis/shipspace1/Plane1.j3o",
                0.f, 
                new Vector3f(0.f,0.f, 0.f),
                1.f,
                Entity.PhysicsType.KINEMATIC);
        
        ship.setRayCastable(false);
        mainChar=ship.getSpatial();
        
        entities.put("ship",ship);
        entities.put("wall",wall);
        entities.put("goal",goal);
        entities.put("e1",enemy1);
        entities.put("e2",enemy2);
        entities.put("e3",enemy3);
        entities.put("e4",enemy4);
//        entities.put("coin",coin);
//        entities.put("star",star);
        
        // attachEntities before setting controls ! --> raycastable node is used by them !
        attachEntities();
        createLightning();
        
         // A camera control is attached to the ship
        new CameraControl(Game.getApp().getCamera(),ship);
        
        // Don't forget to set loaded=true
        loaded=true;
    }
    
    public void start(BaseCommand bc)
    {
        Entity ship = entities.get("ship");
        Entity goal = entities.get("goal");
        Entity e1 = entities.get("e1");
        Entity e2 = entities.get("e2");
        Entity e3 = entities.get("e3");
        Entity e4 = entities.get("e4");
        
        // Adding controls
        ship.addCommandControl(bc);
//        ship.getSpatial().getControl(RigidBodyControl.class).setEnabled(true);
        ship.addControl(new LooseCollisionControl());
        e1.addControl(new PatrolControl(Vector3f.UNIT_X, new Vector3f(0f,10f,-40f),e1.getSpatial()));
        e2.addControl(new PatrolControl(Vector3f.UNIT_X.mult(-1), new Vector3f(0f,10f,20f),e2.getSpatial()));
        e3.addControl(new PatrolControl(Vector3f.UNIT_X, new Vector3f(0f,10f,80f),e3.getSpatial()));
        e4.addControl(new PatrolControl(Vector3f.UNIT_X.mult(-1), new Vector3f(0f,10f,140f),e4.getSpatial()));
        
        goal.addControl(new WinCollisionControl());
        
        //timer
//        levelNode.addControl(new EndTimerControl(10f));
    }
    
}
